package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Education;
import cn.wolfcode.crm.service.IEducationService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("education")
public class EducationController {
    @Autowired
    private IEducationService educationService;

    @RequiresPermissions("education:index")
    @PermissionName("教育首页")
    @RequestMapping("index")
    public String index() {
        return "education/list";
    }





    @RequiresPermissions("education:save")
    @PermissionName("教育保存")
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(Education education){
        JsonResult result = new JsonResult();
        try {
            educationService.insert(education);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("保存教育失败");
        }
        return result;
    }

    @RequiresPermissions("education:update")
    @PermissionName("教育编辑")
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(Education education){
        JsonResult result = new JsonResult();
        try {
            educationService.updateByPrimaryKey(education);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("更新教育失败");
        }
        return result;
    }

    @RequiresPermissions("education:saveOrUpdate")
    @PermissionName("教育编辑")
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(Education education , Long id){
        JsonResult result = new JsonResult();
        try {
            if (id!=null) {
                educationService.updateByPrimaryKey(education);
            }else {
                educationService.insert(education);

            }
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("更新家庭失败");
        }
        return result;
    }
    @RequestMapping("queryByEmpId")
    @ResponseBody
    public List<Education> queryByEmpId(Long id){
        return educationService.queryByEmpId(id);
    }


}
